#!/bin/bash
#author: TFly

if [ "$UID" -ne 0 ]; then
    echo "请使用 sudo 运行此脚本。"
    exit 1
fi
. /etc/os-release 

echo -e "\033[0;32m一键换源系统软件源脚本\n本脚本只支持 Ubuntu 18、20、22\033[0m"
echo "正在备份原来的系统软件源...."
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sleep 2;
echo "已备份至 /etc/apt/sources.list.bak "
source="# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释\ndeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ $UBUNTU_CODENAME main restricted universe multiverse\n# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ $UBUNTU_CODENAME main restricted universe multiverse\ndeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ $UBUNTU_CODENAME-updates main restricted universe multiverse\n# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ $UBUNTU_CODENAME-updates main restricted universe multiverse\ndeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ $UBUNTU_CODENAME-backports main restricted universe multiverse\n# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ $UBUNTU_CODENAME-backports main restricted universe multiverse\n# 以下安全更新软件源包含了官方源与镜像站配置，如有需要可自行修改注释切换\ndeb http://security.ubuntu.com/ubuntu/ $UBUNTU_CODENAME-security main restricted universe multiverse\n# deb-src http://security.ubuntu.com/ubuntu/ $UBUNTU_CODENAME-security main restricted universe multiverse\n# 预发布软件源，不建议启用\n# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ $UBUNTU_CODENAME-proposed main restricted universe multiverse\n# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ $UBUNTU_CODENAME-proposed main restricted universe multiverse"
echo "正在更新源(默认清华源)...."
sudo echo -e $source > /etc/apt/sources.list
sleep 2;
echo -e "更新成功，请输入：\nsudo apt update"


